package com.edu.controller;

import com.edu.common.*;
import com.edu.pojo.Ebook;
import com.edu.service.EbookService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author five-five
 * @createTime 星期一
 */
@RestController
@RequestMapping("/ebook")
@Api("电子书查询接口相关")
public class EbookController {
    @Resource
    private EbookService ebookService;


    @ApiOperation("查询所有电子书")
    @GetMapping("/getAll")
    public CommonResp<List<Ebook>> getAll() {
        CommonResp<List<Ebook>> ebookCommonResp = new CommonResp<>();
        ebookCommonResp.success(ebookService.getAll());
        return ebookCommonResp;
    }

    //    @EnableLogAspect
    @ApiOperation("根据条件查询Ebook")
    @GetMapping("/getEbook")
    public CommonResp<PageResp<EbookResp>> getEbook(
            @ApiParam("ebookReq")
            @Valid EbookReq ebookReq) {
        CommonResp<PageResp<EbookResp>> commonResp = new CommonResp<>();
        //返回成功
        commonResp.success(ebookService.getEbook(ebookReq));
        return commonResp;
    }

    @PostMapping("/save")
    public CommonResp<Void> save(@RequestBody EbookSaveReq req) {
        CommonResp<Void> resp = new CommonResp<>();
        ebookService.save(req);
        return resp;

    }

    @DeleteMapping("/delete/{id}")
    public CommonResp<Void> delete(@PathVariable Long id) {
        CommonResp<Void> resp = new CommonResp<>();
        ebookService.delete(id);
        resp.success(null);
        return resp;
    }

}
